<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <link rel="stylesheet" href="../../static/assets/css/zpui.css" />
    <link rel="stylesheet" href="../../static/assets/css/all.css" />
    <script src="../../static/assets/js/page.js"></script>

    <title> 返款明细 </title>
</head>

<body>
    <div class="page">
        <div class="page-hd">
            <div class="header bor-1px-b">
                <div class="header-left">
                    <a href="javascript:history.go(-1)" class="left-arrow"></a>
                </div>
                <div class="header-title">返款明细</div>
                <div class="header-right">
                    <a href="#"></a>
                </div>
            </div>
        </div>

        <div class="page-bd">
            <!-- 页面内容-->
            <div class="weui-tab">
                <div class="weui-navbar">
                    <a class="weui-navbar__item weui-bar__item--on" id="1" href="#tab1">
                        返利付款
                    </a>
                    <a class="weui-navbar__item" href="#tab1" id="2">
                        待付款
                    </a>
                </div>
                <div class="weui-tab__bd">
                    <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active shop-list">
                        <div class="weui-cells card-box" id="sspa">

                        </div>
                    </div>
                </div>
            </div>

            <!--<div class="fs24 text-muted tc mt30">已经到底啦~</div>-->
        </div>
    </div>

    <script src="../../static/assets/js/lib/jquery-2.1.4.js"></script>
    <script src="../../static/assets/js/jquery-weui.min.js"></script>
    <script src="../../static/assets/js/lib/fastclick.js"></script>
    <script src="../../static/tpl/js/art-template.js"></script>
    <script src="../../static/mobile/default/js/page.js"></script>

    <script>
        let type = 1;
        let page = 1;
        let html = "";
        let boole = true;
        $('.weui-navbar__item').on('click',function () {
            type = $(this).attr('id');
            html = '';
            page = 1;
            getList();
        })

        $(function() {
            FastClick.attach(document.body);
            getList();
            var nScrollHight = 0; //滚动距离总长(注意不是滚动条的长度)
            var nScrollTop = 0;   //滚动到的当前位置
            var nDivHight = $("#tab1").height();
            $("#tab1").scroll(function(){
                nScrollHight = $(this)[0].scrollHeight;
                nScrollTop = $(this)[0].scrollTop;
                if(nScrollTop + nDivHight >= nScrollHight)
                {
                    html = '';
                    getList();
                }
            });
        })
        //getList();
        //请求列表数据
        function getList() {
            $('#jz').show().text('内容加载中~');
            $.ajax({
                url: '/user/userapi/rebatelog/p/'+page+'.html', // 跳转到 action
                data: {
                    'type': type
                },
                type: 'post',
                cache: false,
                headers:{'token': $.cookie('code')},
                            dataType: 'json',
                success:function (res) {
                    for(var i = 0; i < res.list.length; i++){
                        let state = '待付款';
                        if(res.list[i].payer == 1){
                            state = '已付款';
                        }
                        let states = '待确认';
                        if(res.list[i].payee == 1){
                            states = '<span style="color:#6f6f6f;">已完成</span>';

                        }
                        let money = "+"+res.list[i].money;
                        if(res.list[i].Less_user_id == res.UID){
                            money = "-"+res.list[i].money;
                        }
                        html += "                            <a href='/user/user/particulars/id/"+res.list[i].id+"'><div class=\"weui-cell\">\n" +
                            "                                <div class=\"weui-cell__bd\">\n" +
                            "                                    <div>\n" +
                            "                                        <span class=\"fs26 fw600\">"+state+"-"+res.list[i].Less_user_id+"</span>\n" +
                            "                                    </div>\n" +
                            "                                    <div class=\"fs24 text-muted\">"+dateTrans(res.list[i].time * 1000)+"</div>\n" +
                            "                                </div>\n" +
                            "                                <div class=\"weui-cell__ft\">\n" +
                            "                                    <div class=\"fs26 text-red\">"+states+"</div>\n" +
                            "                                    <div class=\"fs28 fw600 font_number text-default\">"+money+"</div>\n" +
                            "                                </div>\n" +
                            "                            </div></a>";
                    }
                    if(res.list.length == 0 && page == 1){
                        html = "<div class=\"empeyOrder\" style=\"width: 100%;text-align: center;\">\n" +
                            "                <img style=\"width: 100%;\" src=\"/static/mobile/default/images/emptyData.png\" alt=\"\">\n" +
                            "                <span class=\"fs24 text-muted tc mt30\">暂无记录</span>\n" +
                            "            </div>";
                    }

                    if(page != 1){
                        if(res.list.length < 20 && boole == true){
                            $('#tab1').append("<div class=\"fs24 text-muted mt30 tc\">已经到底啦~</div>");
                            boole = false;
                        }
                        $('.weui-cells').append(html);
                    }else{
                        $('.weui-cells').html(html);
                    }
                    page = res.page + 1;
                }
            });
        }
        function dateTrans(date) {
            let _date = new Date(parseInt(date));
            let y = _date.getFullYear();
            let m = _date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            let d = _date.getDate();
            d = d < 10 ? ('0' + d) : d;
            let h = _date.getHours();
            h = h < 10 ? ('0' + h) : h;
            let minute = _date.getMinutes();
            let second = _date.getSeconds();
            minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second;
            // console.log( y + '-' + m + '-' + d + ' ' + '　' + h + ':' + minute + ':' + second)
            let dates = m + '月' + d + '日 ' + h + ':' + minute;

            return dates;
        }
    </script>

</body>

</html>